package com.cloud.cloudvideo.controller;

import java.sql.Connection;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.transaction.jta.SpringJtaSynchronizationAdapter;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cloud.cloudvideo.entity.ResultModel;
import com.cloud.cloudvideo.entity.SysGroup;
import com.cloud.cloudvideo.service.GroupService;

@Controller
@RequestMapping("/group")
public class GroupController {

	@Autowired
	private GroupService groupService;

	@RequestMapping("/list")
	@ResponseBody
	public ResultModel<List<SysGroup>> grouplist() {
		List<SysGroup> list = groupService.grouplist();
		return new ResultModel<List<SysGroup>>(list.size(), list);
	}

	@RequestMapping("/toAdd")
	public String toAdd(Model model, @RequestParam("type") Integer type, @RequestParam("parentId") Integer parentId) {
//		model.addAttribute("type", type + 1);
		SysGroup group = new SysGroup();
		type = type+1;
		group.setType(type.byteValue());
		group.setParentId(parentId.longValue());
		model.addAttribute("group", group);
		return "/manager/group/group_add";
	}
	
	@RequestMapping("/toModify")
	public String toModify(Model model, @RequestParam("id") Integer id) {
		SysGroup group = groupService.groupInfo(id);
		model.addAttribute("group", group);
		return "/manager/group/group_add";
	}

	
	@RequestMapping("/add")
	@ResponseBody
	public ResultModel add(SysGroup group) {
		groupService.modifyGroup(group);
		return ResultModel.successWithNoData();
	}
	
	
	@RequestMapping("/del")
	@ResponseBody
	public ResultModel del(@RequestParam("id")Integer id) {
		groupService.delete(id.longValue());
		return ResultModel.successWithNoData();
	}

   
   


        /**
            测试冲突111
            */
	@RequestMapping("/del_test1")
	@ResponseBody
	public ResultModel del_test111(@RequestParam("id")Integer id) {
		//groupService.delete(id.longValue());
		return ResultModel.successWithNoData();
	}

}
